-
Notifications
You must be signed in to change notification settings - Fork 239
Don't fetch block numbers nor check rpc version for ignored tests #3742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
crates/forge/src/test_filter.rs
Outdated
IgnoredFilter::Ignored => { | ||
assert!(ignored); | ||
true | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think we should be including this change, it's technically true given our current logic, but I think it's safer to still check if the test is ignored here since it's not very expensive.
fork_config: if case.config.ignored { | ||
None | ||
} else { | ||
resolve_fork_config(case.config.fork_config, block_number_map, fork_targets) | ||
.await? | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't correct, in case forge is run with --ignored
or --include-ignored
, they will not have their configs resolved.
We should probably split separate the steps test_target_with_config
and resolve_config
and call them as separate methods, not as a part of test_package_with_config_resolved
.
Then we can pass TestsFilter
to resolve_config
and call resolve_fork_config
based on if should_be_run
is true for a test case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could probably make do without splitting from test_package_with_config_resolved
and just passing TestFilter
to the method, but it seems a bit weird to me to use test filter without we even did any kind of filtering with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing tests_filter
to test_package_with_config_resolved
would require marking the ignored_filter
field pub
, that looks like a change that would be needing approval?
Filtering is being done there, tests which the fork config should be resolved or not is going to be dependent on the tests_filter
argument being passed there, if it wasn't for that, then we'll be running into the issue described above, unless there's another way to resolve that.
fork_config: if ignored && matches!(ignored_filter, IgnoredFilter::NotIgnored) { | ||
None | ||
} else { | ||
resolve_fork_config(case.config.fork_config, block_number_map, fork_targets) | ||
.await? | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are duplicating the filtering logic here, why not use TestsFilter.should_be_run
instead?
If the test isn't going to be run for whatever reason (including being ignored), then we don't need to resolve fork config for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried using TestsFilter.should_be_run
but it expects test_case: &TestCaseWithResolvedConfig
while in this scenario, the test case being filtered is TestCase<TestCaseConfig>
that's why I did that, also worth mentioning that TestsFilter.should_be_run
would require me sharing the whole TestsFilter
instance instead of just the needed ignored_filter
field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried using TestsFilter.should_be_run but it expects test_case: &TestCaseWithResolvedConfig while in this scenario, the test case being filtered is TestCase
What could be done in that case is we should introduce a trait that both TestCaseConfig
and TestCaseResolvedConfig
that contains one method like is_ignored
. Then should_be_run
and relevant TestCaseFilter
can be made generic, so they take TestCase<T>
where T implements the introduced trait.
This way it can be reused between both test_case types and logic can be shared.
also worth mentioning that TestsFilter.should_be_run would require me sharing the whole TestsFilter instance instead of just the needed ignored_filter field.
Passing a reference to it to the function doesn't incur any significant cost
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @cptartur I did implement this, and requested a review from you, looking forward to getting it reviewed at your earliest convenience
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also add some tests checking if fork configs get properly resolved (or not resolved) based on the ignored filter.
fork_config: if ignored && tests_filter.should_be_run(&case) { | ||
None | ||
} else { | ||
resolve_fork_config(case.config.fork_config, block_number_map, fork_targets) | ||
.await? | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the condition should be flipped. Also, just checking for if the tests should be run should suffice, we don't need to also check if it was ignored.
fork_config: if ignored && tests_filter.should_be_run(&case) { | |
None | |
} else { | |
resolve_fork_config(case.config.fork_config, block_number_map, fork_targets) | |
.await? | |
}, | |
fork_config: tests_filter.should_be_run(&case) { | |
resolve_fork_config(case.config.fork_config, block_number_map, fork_targets) | |
.await? | |
} else { | |
None | |
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flipped, thanks for mentioning, this sounds more intuitive actually.
crates/forge/src/test_filter.rs
Outdated
impl Default for TestsFilter { | ||
fn default() -> Self { | ||
Self { | ||
name_filter: NameFilter::All, | ||
ignored_filter: IgnoredFilter::All, | ||
last_failed_filter: false, | ||
skip_filter: Vec::new(), | ||
failed_tests_cache: FailedTestsCache::default(), | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the default is just for tests, let's implement it behind #[cfg(tests)]
. I don't think it's a good idea to have a default for this kind of structure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've put it behind #[cfg(test)]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it will be easier to just create this in tests directly, as I wrote in the comment above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see a bunch of tests is failing, not sure if due to changes from this PR. Maybe try updating from master
let ignored = | ||
case.config.ignored || (env_ignore_fork_tests && case.config.fork_config.is_some()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be inlined again
let ignored = | ||
case.config.ignored || (env_ignore_fork_tests && case.config.fork_config.is_some()); | ||
test_cases.push(TestCaseWithResolvedConfig { | ||
config: TestCaseResolvedConfig { | ||
available_gas: case.config.available_gas, | ||
ignored, | ||
fork_config: if tests_filter.should_be_run(&case) { | ||
resolve_fork_config(case.config.fork_config, block_number_map, fork_targets) | ||
.await? | ||
} else { | ||
None | ||
}, | ||
expected_result: case.config.expected_result, | ||
fuzzer_config: case.config.fuzzer_config, | ||
disable_predeployed_contracts: case.config.disable_predeployed_contracts, | ||
}, | ||
name: case.name, | ||
test_details: case.test_details, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's try not modify code that is not relevant to the PR changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This right here was due to Rust reporting a partial move, the name
, test_details
, expected_result
, fuzzer_config
, disable_predeployed_contracts
don't implement copy, so they get partially moved, before I try to borrow &case
in should_be_run
. This is why I modified it to be that way.
BlockId::BlockNumber(100), | ||
)]; | ||
|
||
let tests_filter = TestsFilter::default(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be clearer to create one directly here otherwise you have to know the implementation of default to know if this test makes sense.
crates/forge/src/test_filter.rs
Outdated
impl Default for TestsFilter { | ||
fn default() -> Self { | ||
Self { | ||
name_filter: NameFilter::All, | ||
ignored_filter: IgnoredFilter::All, | ||
last_failed_filter: false, | ||
skip_filter: Vec::new(), | ||
failed_tests_cache: FailedTestsCache::default(), | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it will be easier to just create this in tests directly, as I wrote in the comment above.
The failing tests seem to look like they all expect std contains some text... |
Closes #1637
Introduced changes
Block number and RPC version for ignored tests is no longer being checked
fork_config
returnsNone
for ignored testsshould_be_run
IgnoredFilter::Ignored
match arm asserts that test case is ignored.Checklist
CHANGELOG.md